<template>
	<view class="resourceList">
		<uni-row style="margin-top: 8rpx;margin-bottom: 20rpx;">
			<uni-col :span="2" style="padding-top: 7rpx;">
				<uni-icons type="list" size="32"></uni-icons>
			</uni-col>
			<uni-col :span="18" style="padding-left: 20rpx;">
				<uni-easyinput style="background-color: #fff;" suffixIcon="search" v-model="queryParams.number"
					placeholder="报工单号" @iconClick="queryClick"></uni-easyinput>
			</uni-col>
			<uni-col :span="4" style="padding-left: 8rpx;padding-top: 7rpx;">
				<uni-icons type="scan" size="32"></uni-icons>
			</uni-col>
		</uni-row>
		<view v-for="(item,index) in reportList" style="margin-top: 10rpx;">
			<uni-row class="resourceList-uni-row">
				<text style="font-size: 18px;font-weight:bold;">
					报工单:&nbsp;&nbsp;&nbsp;{{item.number}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					报工时间:&nbsp;&nbsp;&nbsp;{{item.reportTime}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					报工人:&nbsp;&nbsp;&nbsp;{{item.reportUserName}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					工单:&nbsp;&nbsp;&nbsp;{{item.workOrderNumber}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					产品:&nbsp;&nbsp;&nbsp;{{item.materialName}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					工序:&nbsp;&nbsp;&nbsp;{{item.processName}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<uni-col :span="24">
					<text class="resourceList-text">
						报工数:&nbsp;&nbsp;&nbsp;{{item.reportQuantity}}
					</text>
				</uni-col>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					合格数:&nbsp;&nbsp;&nbsp;{{item.qualifiedQuantity}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<uni-col :span="9">
					<text class="resourceList-text">
						结算工资:&nbsp;&nbsp;&nbsp;{{item.wages}}
					</text>
				</uni-col>
				<uni-col :span="5">
					<view v-if="item.isSettle=='Y'" class="tag-view" style="margin-top: 6rpx;">
						<uni-tag :circle="true" text="已结算" type="error" />
					</view>
					<view v-if="item.isSettle=='N'" class="tag-view" style="margin-top: 6rpx;">
						<uni-tag :circle="true" text="未结算" type="error" />
					</view>
				</uni-col>
				<uni-col :span="5">
					<view v-if="item.qualityStatus=='A'" class="tag-view" style="margin-top: 6rpx;">
						<uni-tag :circle="true" text="免检" type="error" />
					</view>
					<view v-if="item.qualityStatus=='B'" class="tag-view" style="margin-top: 6rpx;">
						<uni-tag :circle="true" text="待质检" type="error" />
					</view>
					<view v-if="item.qualityStatus=='C'" class="tag-view" style="margin-top: 6rpx;">
						<uni-tag :circle="true" text="质检通过" type="error" />
					</view>
				</uni-col>
				<uni-col :span="5">
					<button style="padding: 0rpx; height: 57rpx;width: 120rpx;" plain="true" size="mini" type="primary"
						@click="addReportQuality(item)">
						<text style="font-size: 4;">质检单</text>
					</button>
				</uni-col>
			</uni-row>
			<uni-row>
				<text class="resourceList-text">
					备注:&nbsp;&nbsp;&nbsp;{{item.remark}}
				</text>
			</uni-row>
		</view>
		<uni-load-more :status="loadStatus"  />
		<reportQualityForm ref="reportQualityForm"> </reportQualityForm>
	</view>

</template>

<script>
	import {
		listReport,
		getReport,
	} from "@/api/production/report";
	import {
		getUserProfile
	} from "@/api/system/user"
	import {
		getDicts
	} from "@/api/system/dict/data";
	import reportQualityForm from "@/pages/quality/reportQuality/form.vue";
	import pdaScan from "@/components/mes/pdaScan.vue"
	export default {
		components: {
			reportQualityForm,
		},
		data() {
			return {
				queryParams: {
					pageSize: 5,
					pageNum: 1
				},
				//报工单列表
				reportList: [],
				user: {},
				loadStatus: "more"
			}
		},
		onShow: function() {  
		        /* var _this = this  
		        uni.$off('scancodedate') // 每次进来先 移除全局自定义事件监听器  
		        uni.$on('scancodedate',function(data){  
		            console.log('你想要的code：', data.code)
					  _this.queryParams.number=data.code;
					  _this.queryClick();
		        })  */
		    }  ,
		 onReachBottom() {
			 this.clickLoadMore()
		 },
		created() {
			this.getUser();
			this.getList();
		},
		methods: {
			/** 查询报工单列表 */
			getList() {
				this.queryParams.reportUserId = this.user.userId;
				listReport(this.queryParams).then(reportResponse => {
					let total =reportResponse.total;
					let list = reportResponse.rows;
					//已查询出来的和新查询的 大于等于total总页数，表示no-more
					if (list.length+this.reportList.length >=total) {
						this.loadStatus = "no-more"
					} else {
						this.loadStatus = "more"
					}

					if (this.reportList.length > 0) {
						this.reportList = this.reportList.concat(list)
					} else {
						this.reportList = list;
					}

				})
			},
			getUser() {
				getUserProfile().then(response => {
					this.user = response.data
				})
			},
			//点击新增质检
			addReportQuality(report) {
				this.$refs.reportQualityForm.openPopup(report);
			},
			queryClick() {
				this.queryParams.pageNum = 1
				this.reportList = []
				this.getList();
			},
			clickLoadMore() {
				if (this.loadStatus === "no-more") {
					return;
				}
				this.loadStatus = "loading"
				this.queryParams.pageNum += 1;
				this.getList();
			}
		},
	}
</script>

<style>
	.resourceList-uni-row {
		margin-bottom: 8rpx;
	}

	.resourceList-text {
		font-size: 16px;
	}

	.resourceList {
		margin-left: 10px;

	}
</style>
